package com.apartment.sevice.impl;

import com.apartment.dao.ServeDao;
import com.apartment.data.entity.Apartment;
import com.apartment.data.entity.Collect;
import com.apartment.sevice.ServeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Author : xuzhiyong
 * Date : 2022/6/5 22:23
 */
@Service
public class ServeServiceImpl implements ServeService {

    @Autowired
    private ServeDao serveDao;

    @Override
    public boolean addCollect(Collect collect) {
        boolean flag = false;
        try {
            serveDao.save(collect);
            flag = true;
        }catch (Exception e){
            System.out.println("收藏失败");
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public List<Collect> findCollectByUserId(Integer id) {
        return serveDao.finCollectByUserId(id);
    }

    @Override
    public boolean deleteCollectById(Integer id) {
        boolean flag = false;
        try {
            serveDao.deleteById(id);
            flag = true;
        }catch (Exception e){
            System.out.println("收藏失败");
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public List<Map<String, Object>> findApartmentByLike(String keyword) {
        return serveDao.findApartmentByLike(keyword);
    }
}
